package com.runa.persistence.service;

import com.alibaba.fastjson.JSON;
import com.runa.monitor.comm.entity.EntityErrorLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 2024/7/15 14:15
 * zhangYB
 */
@Slf4j
@Service
public class InvokeService {

    private static ErrorLogService errorLogService;


    @Resource
    public void setErrorLogService(ErrorLogService errorLogService) {
        this.errorLogService = errorLogService;
    }


    public static void saveInstructLog(String serialNo, String netSerial, String status, String request, List<String> responses) {
        try {
            EntityErrorLog entityErrorLog = new EntityErrorLog();
            entityErrorLog.setNode("COMM:INSTRUCT:" + serialNo + ":" + status);
            entityErrorLog.setIdentify(netSerial + ":" + serialNo + ":" + status);
            entityErrorLog.setEvent(status);
            entityErrorLog.setOrderCode(request);
            entityErrorLog.setContent(JSON.toJSONString(responses));
            errorLogService.save(entityErrorLog);
        } catch (Exception e) {
            log.error("InvokeService.saveInstructLog error: ", e);
        }
    }


}
